package com.micro.mic_business.order.controller;

import com.micro.mic_business.order.service.UserService;
import com.micro.mic_business.order.vo.OrderVo;
import com.micro.mic_business.order.vo.UserVo;
import com.micro.mic_common.utils.RedisCommonUtil;
import com.micro.mic_common.utils.ResponseDataUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author yijian
 * @Date 2021/12/23 14:47
 **/
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {


    @Autowired
    private UserService userService;

    @Autowired
    private RedisCommonUtil redisCommonUtil;

    @RequestMapping("/ok/{name}/{age}")
    public String order(@PathVariable("name") String name,@PathVariable("age") int age){
        OrderVo orderVo = new OrderVo(name,age);
        redisCommonUtil.set(name,orderVo);
        log.info("*****获取key:"+redisCommonUtil.get(name));
        return redisCommonUtil.get(name).toString();
    }

    @RequestMapping("/user/{id}")
    public Object user(@PathVariable("id") long userId){
        UserVo userVo = userService.queryUserById(userId);
        return ResponseDataUtil.success(userVo);
    }

    @RequestMapping("/insertUser/{name}/{age}")
    public Object insertUser(@PathVariable("name") String name,@PathVariable("age") int age){
        UserVo userVo = new UserVo(name,age);
        userService.insertUserInfo(userVo);
        return ResponseDataUtil.success();
    }
}
